'use strict';

/* Controllers */
// signin controller
app.controller('ForgotPwdController', ['$scope', '$state','$stateParams', '$cookieStore','$interval','AccountService', function ($scope, $state,$stateParams,$cookieStore,$interval, accountService) {
    $scope.sendtext = "发送验证码";
    $scope.sendCode = function(){
        $scope.errInfo = "";
        $scope.sending = true;
        accountService.sendCode({phone:$scope.phone,type:2}).then(function (response) {
            if (response.code == 0) {
                var second = 60, timePromise = undefined;

                timePromise = $interval(function(){
                    if(second <= 0){
                        $interval.cancel(timePromise);
                        $scope.sending = undefined;
                        second = 60;
                        $scope.sendtext = "重发验证码";
                    }else{
                        $scope.sendtext = second + "秒后可重发";
                        second--;

                    }
                },1000,100);

            } else {
                $scope.sending = undefined;
                $scope.errInfo = response.message;
            }
        }, function (fail) {
            //服务器出错
        });

    }
}])
;